package com.qf.listen;

import com.qf.config.SendEmailUtil;
import com.qf.pojo.common.MailBean;
import com.qf.pojo.common.RedisDic;
import com.qf.utils.RedisUtils;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Random;

@Component
public class MailListen {


    @Autowired
    private SendEmailUtil sendEmailUtil;

    @Autowired
    private RedisUtils redisUtils;



    @RabbitListener(queues = "sendMail")
    public void sendMail(String mail){
        Random random = new Random();
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < 4; i++){
            stringBuffer.append(random.nextInt(10));
        }
        MailBean mailBean = new MailBean();
        mailBean.setRecipient(mail);
        mailBean.setSubject("学期网在线教育平台验证码");
        mailBean.setContent(stringBuffer.toString());
        sendEmailUtil.sendManage(mailBean);
        redisUtils.hset(RedisDic.REDIS_EMAIL_KEY, mail, stringBuffer.toString(), 60*5);

    }
}
